package dnet

import (
	"bufio"
	"strings"
)

const (
	FTP_CMD_USER string = "USER"
	FTP_CMD_PASS string = "PASS"
	FTP_CMD_SYST string = "SYST"
	FTP_CMD_TYPE string = "TYPE"
	FTP_CMD_PASV string = "PASV"
	FTP_CMD_CWD  string = "CWD"
	FTP_CMD_AUTH string = "AUTH"

	FTP_STATUS_SUCC         = 200 // 成功
	FTP_STATUS_SERV_READY   = 220 // 服务就绪
	FTP_STATUS_PASV         = 227 // passive
	FTP_STATUS_USER_OK      = 331 // RFC 959, 4.2.1
	FTP_STATUS_LOGIN_OK     = 230 // 登陸成功
	FTP_STATUS_CMD_INVALID  = 500 // 无效命令
	FTP_STATUS_LOGIN_FAIL   = 530 //未登錄
	FTP_STATUS_PATH_READY   = 257
	FTP_STATUS_FILE_INVALID = 550
)

func getMessageLines(message string) []string {
	lines := make([]string, 0, 1)
	sc := bufio.NewScanner(strings.NewReader(message))

	for sc.Scan() {
		lines = append(lines, sc.Text())
	}

	if len(lines) == 0 {
		lines = append(lines, "")
	}

	return lines
}

func parseFtpCmdLine(line string) (string, string) {
	params := strings.SplitN(line, " ", 2)
	if len(params) == 1 {
		return params[0], ""
	}

	return params[0], params[1]
}
